home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / fsovl / init.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  3KB  |  152 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6.  
  7. /*
  8.  * INIT.C - initialize DOS handler functions
  9.  */
  10.  
  11. #include "defs.h"
  12.  
  13. Prototype void Initialize(char *name);
  14. Prototype void UnInitialize(void);
  15. Prototype MsgPort *FindDosDevice(char *name, short len, BPTR *plock);
  16.  
  17. Prototype DosList *Dl;
  18. Prototype MsgPort *PktPort;
  19. Prototype MsgPort *AuxPort;
  20. Prototype long    PktPortMask;
  21. Prototype struct DosLibrary *DOSBase;
  22.  
  23. void MkDevice(char *devName);
  24. void DelDevice(void);
  25.  
  26. DosList *Dl;
  27. MsgPort *PktPort;
  28. MsgPort *AuxPort;
  29. long    PktPortMask;
  30.  
  31. void
  32. Initialize(char *name)
  33. {
  34.     Process *proc = FindTask(NULL);
  35.  
  36.     /*
  37.      *    Initialize port
  38.      */
  39.  
  40.     PktPort = CreatePort(NULL, 0);
  41.     AuxPort = CreatePort(NULL, 0);
  42.     PktPortMask = 1 << PktPort->mp_SigBit;
  43.  
  44.     /*
  45.      *    create DOS node
  46.      */
  47.  
  48.     MkDevice(name);
  49. }
  50.  
  51. void
  52. UnInitialize()
  53. {
  54.     DelDevice();
  55.     if (PktPort) {
  56.     DeletePort(PktPort);
  57.     PktPort = NULL;
  58.     }
  59.     if (AuxPort) {
  60.     DeletePort(AuxPort);
  61.     AuxPort = NULL;
  62.     }
  63. }
  64.  
  65. /*
  66.  * note: devName is a CPTR to a BSTR
  67.  */
  68.  
  69. void
  70. MkDevice(devName)
  71. char *devName;
  72. {
  73.     DosList *dl;
  74.     RootNode *root;
  75.     DosInfo *info;
  76.  
  77.     Dl = dl = DosAlloc(sizeof(struct DosList));
  78.     dl->dol_Type = DLT_DEVICE;
  79.     dl->dol_Task = PktPort;
  80.     dl->dol_Name = CTOB(devName);
  81.  
  82.     Forbid();
  83.     root  = (struct RootNode *)DOSBase->dl_Root;
  84.     info  = (struct DosInfo  *)BADDR(root->rn_Info);
  85.     dl->dol_Next = info->di_DevInfo;
  86.     info->di_DevInfo = CTOB(dl);
  87.     Permit();
  88. }
  89.  
  90. void
  91. DelDevice()
  92. {
  93.     DosList *dl;
  94.     DosInfo *info;
  95.     RootNode *root;
  96.     DosList *dls;
  97.     BPTR    *bpp;
  98.  
  99.     if (dl = Dl) {
  100.     Forbid();
  101.     root  = (struct RootNode *)DOSBase->dl_Root;
  102.     info  = (struct DosInfo  *)BTOC(root->rn_Info);
  103.  
  104.     for (bpp = &info->di_DevInfo; dls = BTOC(*bpp); bpp = &dls->dol_Next) {
  105.         if (dls == dl)
  106.         break;
  107.     }
  108.     if (dls == dl) {
  109.         *bpp = dls->dol_Next;
  110.     } else {
  111.         ;
  112.     }
  113.     Permit();
  114.     DosFree(dl);
  115.     Dl = NULL;
  116.     }
  117. }
  118.  
  119. MsgPort *
  120. FindDosDevice(char *name, short len, BPTR *plock)
  121. {
  122.     DosInfo *info;
  123.     RootNode *root;
  124.     DosList *dls;
  125.     BPTR    *bpp;
  126.  
  127.     *plock = 0;
  128.  
  129.     Forbid();
  130.     root  = (struct RootNode *)DOSBase->dl_Root;
  131.     info  = (struct DosInfo  *)BTOC(root->rn_Info);
  132.  
  133.     for (bpp = &info->di_DevInfo; dls = BTOC(*bpp); bpp = &dls->dol_Next) {
  134.     ubyte *ptr = BTOC(dls->dol_Name);
  135.     if (len == *ptr && strnicmp(name, ptr + 1, len) == 0) {
  136.         if (dls->dol_Type == DLT_DEVICE) {
  137.             break;
  138.         } else if (dls->dol_Type == DLT_VOLUME) {
  139.         break;
  140.         } else if (dls->dol_Type == DLT_DIRECTORY) {
  141.         *plock = DupLockPacket(dls->dol_Lock);
  142.         break;
  143.         }
  144.     }
  145.     }
  146.     Permit();
  147.     if (dls)
  148.     return(dls->dol_Task);
  149.     return(NULL);
  150. }
  151.  
  152.